const codes = document.querySelectorAll('.code')

codes[0].focus()

codes.forEach((item, index) => {
    item.addEventListener('keydown', (e) => {
        if (e.key >= 0 && e.key <= 9) {
            setTimeout(() => {
                if (codes[index + 1]) {
                    codes[index + 1].focus()
                }
            }, 10)
        } else if (e.key === 'Backspace') {
            setTimeout(() => {
                if (codes[index - 1]) {
                    codes[index - 1].focus()
                }
            }, 10);
        }
    })
})